# coding=utf-8
# 全世界最帅的帅哥
from flask_restful import Resource
from ..subject_views.category_views import get_all_categories, query_category_list, add_category, update_category, \
    delete_category, get_category


class SubjectCategoryResource(Resource):
    """
    刷题分类的资源类
    """

    def get(self, category_id=None, action=None):
        if category_id:
            return get_category(category_id)
        elif action == "query_top_category":
            return get_all_categories()
        elif action == "queryCategoryList":
            return query_category_list()
        return {"code": 500, "message": "wrong request"}

    def post(self):
        """
        新增分类
        :return:
        """
        return add_category()

    def put(self, category_id):
        return update_category(category_id)

    def delete(self, category_id):
        """
        删除分类
        :param category_id:
        :return:
        """
        return delete_category(category_id)
